/* Copyright (c) 2025 Beijing Semidrive Technology Corporation
 * SPDX-License-Identifier: Apache-2.0
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef I2C_TYPES_H_
#define I2C_TYPES_H_
#include "Platform_Types.h"
#include "I2c_Cfg.h"

typedef enum I2c_trans_st
{
    I2C_IDLE_STATE,
    I2C_BUSY_STATE,
    I2C_FAIL_STATE,
    I2C_STUCK_STATE,
    I2C_NACK_STATE,
    I2C_UNDEFINETRANS_STATE,
} I2c_trans_state_t;

typedef enum I2c_recov_st
{
    I2C_CLRERR_STATE,
    I2C_CLRPASS_STATE,
    I2C_UNDEFINERECOV_STATE,
} I2c_recov_state_t;

typedef enum I2c_init_st
{
    I2C_UNINIT_STATE,
    I2C_INIT_STATE,
    I2C_UNDEFINEINIT_STATE,
} I2c_init_state_t;

typedef enum I2c_trans_mod
{
    I2C_POLLING_MOD,
    I2C_MAINFUN_MOD,
    I2C_INTR_MOD,
} I2c_trans_mod_t;

typedef enum I2c_speed
{
    I2C_SSPEED,         /*! @brief Standard Speed 100KHz */
    I2C_FSPEED,         /*! @brief Fast Speed 400KHz */
    I2C_PSPEED,         /*! @brief Fast-Plus Speed 1MHz */
    I2C_HSPEED,         /*! @brief High Speed 3.4MHz */
    I2C_USPEED,         /*! @brief Ultra-Fast Speed 5MHz */
} I2c_speed_t;


typedef enum I2c_opmode
{
    I2C_MASTER,
    I2C_SLAVE,
    SMB_MASTER,
    SMB_SLAVE,
    PM_MASTER,
    PM_SLAVE,
} I2c_opmode_t;

typedef enum
{
    I2C_ADDR7B,
    I2C_ADDR10B,
} I2c_addr_bits_t;

typedef enum
{
    I2C_M_W,
    I2C_M_R,
} I2c_rw_flag_t;

typedef enum
{
    I2C_DIS,
    I2C_EN,
} I2c_chan_en_t;

typedef enum
{
    I2C_ID_1 = 1,
    I2C_ID_2,
    I2C_ID_3,
    I2C_ID_4
} I2c_chan_id;

enum I2c_AdapCurState
{
    I2C_ADAP_IDLE = 0U,
    I2C_ADAP_BUSY
};

typedef int (*I2c_mas_cb_t)(uint8 channelId, I2c_trans_state_t state);

typedef struct I2c_msg
{
    uint16 addr;     /* slave address       */
    uint16 len;      /* msg length          */
    uint8 *buf;      /* pointer to msg data */
    uint8 addr_flag; /* I2C_ADDR7 / I2C_ADDR10 */
    uint32 rw_flag;  /* I2C_M_W / I2C_M_R / I2C_M_NOSTART / I2C_M_REV_DIR_ADDR */
    I2c_trans_mod_t polling;   /* true for polling for special scene, otherwise ignore */
} I2c_msg_t;

typedef struct
{
    uint32 timStuck;
    uint32 timSclh;
    uint32 timSclh_hs;
} I2c_timeCfg_t;

typedef struct
{
    uint32 base;
    I2c_chan_id hwCh;
    uint32 clk;
    I2c_chan_en_t enable;
    enum I2c_opmode opmode;
    enum I2c_speed speed;
    I2c_addr_bits_t addr_flag; /* I2C_ADDR7B / I2C_ADDR10B */
    I2c_trans_mod_t polling;   /* true for polling for special scene, otherwise ignore */
    uint8 i2cCoreId;
    I2c_mas_cb_t I2cNotification;
    uint32 timStuck;
    uint32 timSclh;
    uint32 timSclh_hs;
    I2c_msg_t *msgs;
} I2c_adap_cfg_t;


typedef struct sdrv_I2c_mdev
{
    uint32 timeout;
    void *event;
    int status;
    I2c_msg_t *msgs;
    uint8 num;
    I2c_msg_t *cur_msg;
    uint8 cur_msg_idx;
    int cur_msg_stat;
    int cur_cmd_done;
    uint16 cur_msg_len;
} sdrv_I2c_mdev_t;

typedef struct I2c_adap_dev
{
    uint32 base;
    uint32 clk;
    I2c_chan_en_t enable;
    enum I2c_opmode opmode;
    enum I2c_speed speed;
    I2c_chan_id hwCh;
    I2c_init_state_t status;
    void *priv;
    I2c_trans_state_t trans_state;
    enum I2c_AdapCurState adap_State;
    I2c_mas_cb_t I2cNotification;
    I2c_timeCfg_t i2cTimeCfg;
} I2c_adap_dev_t;




#endif /*I2C_TYPES_H_*/
